package cn.youqu.happy.module.youqu.convert.userAssess;

import cn.hutool.core.collection.CollUtil;
import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.module.youqu.controller.admin.userAssess.vo.*;
import cn.youqu.happy.module.youqu.controller.app.userAssess.vo.AppUserAssessPageReqVO;
import cn.youqu.happy.module.youqu.controller.app.userAssess.vo.AppUserAssessPublishReqVO;
import cn.youqu.happy.module.youqu.controller.app.userAssess.vo.AppUserAssessRespVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userAssess.UserAssessDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 用户评价 Convert
 *
 * @author 王其岩 20112001045
 */
@Mapper(componentModel = "spring")
public interface UserAssessConvert {

    UserAssessConvert INSTANCE = Mappers.getMapper(UserAssessConvert.class);

    UserAssessDO convert(UserAssessCreateReqVO bean);

    UserAssessDO convert(UserAssessUpdateReqVO bean);

    UserAssessRespVO convert(UserAssessDO bean);


    AppUserAssessRespVO convert0(UserAssessDO bean);

    UserAssessUpdateReqVO convert1(UserAssessDO bean);

    List<UserAssessRespVO> convertList(List<UserAssessDO> list);

    PageResult<UserAssessRespVO> convertPage(PageResult<UserAssessDO> page);

    List<UserAssessExcelVO> convertList02(List<UserAssessDO> list);

    List<AppUserAssessRespVO> convertList0(List<UserAssessDO> list);

    UserAssessPageReqVO convert(AppUserAssessPageReqVO pageVO);

    PageResult<AppUserAssessRespVO> convertPage0(PageResult<UserAssessDO> pageResult);

    @Mapping(target = "img", source = "imgList")
    UserAssessDO convert(AppUserAssessPublishReqVO publishReqVO);

    default String list2str(List<String> src) {
        if (CollUtil.isEmpty(src)) {
            return null;
        }
        return String.join(",", src);
    }

    default List<String> str2List(String str) {
        if (str == null || str.isEmpty()) return new ArrayList<>();
        String[] split = str.split(",");
        return Arrays.asList(split);
    }


}
